#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""检查必需工具是否安装"""
import shutil
import sys
from pathlib import Path

REQUIRED_TOOLS = {
    "ruff": "pip install ruff",
    "mypy": "pip install mypy",
    "pytest": "pip install pytest",
    "black": "pip install black",
    "isort": "pip install isort",
}

def check_tools() -> int:
    """检查工具安装状态"""
    missing = []

    for tool, install_cmd in REQUIRED_TOOLS.items():
        if not shutil.which(tool):
            missing.append((tool, install_cmd))

    if missing:
        print("[Pre-commit] 缺少必需工具:\n")
        for tool, cmd in missing:
            print(f"  - {tool}: {cmd}")
        print("\n[Pre-commit] 提示: 运行 'make install' 或 'pip install -r requirements.txt' 安装所有依赖")
        return 1

    print("[Pre-commit] 所有必需工具已安装")
    return 0

if __name__ == "__main__":
    sys.exit(check_tools())
